package com.ruoyi.web.controller.common;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.vo.AddressVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author cws
 * @since
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    StringRedisTemplate redisTemplate;


    @GetMapping("/area")
    @ApiOperation("获取省市区三级联动列表")
    public AjaxResult treeList() {
        if (redisTemplate.hasKey("mall:address")) {
            String res = redisTemplate.opsForValue().get("mall:address");
            List<AddressVo> addressVos = JSON.parseArray(res, AddressVo.class);
            return AjaxResult.success(addressVos);
        }
        return AjaxResult.success();
    }


}

